<?php
namespace Admin\Controller;
use Admin\Controller\AdminBaseController;
use Common\Model\TradeBuyModel;
use Common\Model\TradeSellModel;
use Common\Model\ShopModel;
use Common\Model\ShopBuyModel;
class ShopController extends AdminBaseController{
    public function shoplist()
    {
        $list=ShopModel::newSelf()->pagingList();
        $this->assign('list',$list);
        $this->display();
    }
    public function addShop()
    {
        $this->display();
    }
    public function addShopSub()
    {
        $this->return_type='error';
        $data['name']=I('name');
        $data['money']=I('money');
        
        $this->notEmptyValidate($data['name'],'请填写名称');
        $this->notEmptyValidate($data['money'],'请填写价格');

        $this->egtValidate($data['money'], 0,'请填写正确价格');

        if(!empty($_FILES['image'])){
            $res=$this->uploadOne('image');
            $this->trueValidate($res['status'],$res['info']);
            $data['image']=$res['info'];
        }
            $data['add_time']=time();
        
        $res=ShopModel::newSelf()->add($data);
        $this->resReturn($res, '添加成功', '添加失败');
    }
    public function delShop()
    {
        $id=I('id');
        $res=ShopModel::newSelf()->where(['id'=>$id])->setField('status','-1');

        $this->resReturn($res, '删除成功', '删除失败');
    }
    public function shopBuyLog()
    {
	    if ($_GET['username']) {
           $username=I('username'); 
           $user=$this->findUserByUserName($username);
	       $where['user_id']=$user['id'];
	    }
        $list=ShopBuyModel::newSelf()->pagingList($where);
        $this->assign('list',$list);
        $this->display();
    }
}
